package main

import (
	"fmt"
	"sort"

	NewSet "generic/type_alias"
)

func main() {
	set := NewSet.NewSet[int](4, 1, 2, 3)
	set.Add(4)
	set.Remove(2)

	fmt.Println("Len:", set.Len())
	fmt.Println("Exists 3:", set.Exists(3))
	fmt.Println("Exists 2:", set.Exists(2))

	fmt.Println("Range 遍历：")
	set.Range(func(elem int) bool {
		fmt.Println("  elem:", elem)
		return true
	})

	elems := set.Elements()
	sort.Ints(elems)
	fmt.Println("Sorted elements:", elems)

	a := NewSet.NewSet[string](0, "Go", "Rust", "Java")
	b := NewSet.NewSet[string](0, "Rust", "Python", "Go")

	union := NewSet.Union(a, b)
	inter := NewSet.Intersect(a, b)
	diff := NewSet.Difference(a, b)
	symDiff := NewSet.SymmetricDifference(a, b)

	fmt.Println("Union:", union.Elements())
	fmt.Println("Intersect:", inter.Elements())
	fmt.Println("Difference:", diff.Elements())
	fmt.Println("SymmetricDifference:", symDiff.Elements())

	if NewSet.IsSubset(inter, union) {
		fmt.Println("inter 是 union 的子集")
	}

	raw := set.Map()
	raw[999] = struct{}{}
	fmt.Println("原集合是否包含 999？", set.Exists(999))
}
